'use strict';

import { merchantcashwepayModel } from "../model/merchatcashwepay";
import { ServiceBase, Exceptions } from '../kalend';
import { datadictionaryService } from "./datadictionary";
import { usertokenService } from "./usertoken";
var moment = require('moment');

class MerchantwepaysetService extends ServiceBase {
    constructor() {
        super(merchantcashwepayModel)
    }

    //查询
    async query(doc: any) {
      
        let result: any = await this.queryAll({
          filter: { merchantid: doc.merid,status:1,isdel:false }
      });
       
        return result;
    }
    

    //保存
    async save(doc: any) {
      if(!doc.wechatphone||!doc.wechatrealname||!doc.wechatidnum||!doc.wechatphone||!doc.wechatopenid||!doc.merchantid){
        return '保存失败';
      }
      if (doc._id) {
        this.update(doc._id, doc);
    } else {  
     let res= await this.querySingle({wechatphone:doc.wechatphone,wechatopenid:doc.wechatopenid,merchantid:doc.merchantid});
     if(!res){
      this.create(doc);
     }else{
       return"该账号已存在";
     }
        
    }
    return '保存成功';
    }

    //逻辑删除启用
    async logicdelete(parm: any) {
      return await this.update(parm._id, { isdel:true });
    }

 

   

}

export const merchantwepaysetService = new MerchantwepaysetService();